<?php

namespace Model;
use Think\Model;

class AuthModel extends Model{
    function doadd($arr){
        //①添加不完整信息
        $newid = $this->add($arr);
        //②获取auth_path
        if($arr['auth_pid']==0){
            $auth_path=$newid;
        }else{
            $auth_path = $arr['auth_pid'].'-'.$newid;
        }
        //③获取auth_level
        $auth_level = substr_count($auth_path, '-');
        //④更新auth_path auth_level
       $this->auth_id = $newid;
       $this->auth_path = $auth_path;
       $this->auth_level = $auth_level;
       $info =  $this->save();
       return $info;
    }
    function saveauth($arr,$auth_id){
        $this->where("auth_id=$auth_id")->save($arr);
        if($arr['auth_pid']==0){
            $auth_path=$auth_id;
        }else{
            $auth_path = $arr['auth_pid'].'-'.$auth_id;
        }
        $auth_level = substr_count($auth_path, '-');
        
       $this->auth_id = $auth_id;
       $this->auth_path = $auth_path;
       $this->auth_level = $auth_level;
       $info =  $this->save();
       return $info;
    }
}
